package com.atguigu.day28.work;

import sun.util.resources.cldr.ti.CalendarData_ti_ER;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class Admin {
    private ArrayList<Employee> list;

    public Admin(){
        list=new ArrayList<Employee>();
    }
    public void add(Employee employee){
        list.add(employee);
    }
    public ArrayList<Employee> get(Predicate<Employee> p){
        ArrayList<Employee> all=new ArrayList<>();
        for (Employee employee : list) {
            if (p.test(employee)){
                all.add(employee);
            }
        }
        return all;
    }
    public void remove(Predicate<Employee> p){
        Iterator<Employee> iterator=list.iterator();
        while (iterator.hasNext()){
            Employee next=iterator.next();
            if (p.test(next)){
                iterator.remove();
            }
        }
    }
    public void update(Consumer<Employee> c){
        for (Employee employee : list) {
            c.accept(employee);
        }
    }
    public int size(){
        return list.size();
    }
}
